package com.dr.java.day05;

/**
 * Created by rui on 2017/12/30.
 */
public class PersonDemo {
    public static void main(String[] args) {
        Person p=new Person();
        p.setAge(9);
    }
}

class Person {

//    private是封装的一种表现形式（权限上进行限制就可以实现封装）
    private int age;

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        if (age > 0 & age < 130) {
            this.age = age;
            speak();
        } else {
            System.out.println("error");
        }
        this.age = age;
    }

    private void speak() {
        System.out.println("age=" + this.age);
    }
}
